//Linkwish's code
#include<bits/stdc++.h>
#define endl '\n'
#define si inline
#define fi first
#define se second
using namespace std;
typedef long long ll;typedef __int128 li;typedef long double ld;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef const int ci;typedef const ll cl;ci iinf=INT_MAX;cl linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}

namespace LinkWish{

	ci N=1000005,lim=1e9+10;

	int n,C;
	int a[N];
	vector<int> p[N];

	int c[N],num;

	int las[N];
	vector<int> allp[N];

	struct Hoshino{
		int ls,rs;
		ll t1,t2;
	}t[N*30];
	int rt,cnt;
	void modify(int &x,int l,int r,int L,int R,ll v1,ll v2){
		if(x==0)x=++cnt;
		if(l>=L&&r<=R)return t[x].t1+=v1,t[x].t2+=v2,void();
		int mid=(l+r)>>1;
		if(L<=mid)modify(t[x].ls,l,mid,L,R,v1,v2);
		if(R>mid)modify(t[x].rs,mid+1,r,L,R,v1,v2);
	}

	ll ans;
	vector<int> res;
	void solve(int x,int l,int r,ll t1=0,ll t2=0){
		if(x==0)return ;
		t1+=t[x].t1,t2+=t[x].t2;
		if(t[x].ls==0&&t[x].rs==0){
			if(gmin(ans,t1+l*t2)){
				//cout<<"GMIN "<<l<<' '<<r<<' '<<t1<<' '<<t2<<' '<<t1+l*t2<<endl;
				res.clear();
			}
			if(ans==t1+l*t2)res.push_back(l);
			return ;
		}
		int mid=(l+r)>>1;
		solve(t[x].ls,l,mid,t1,t2);
		solve(t[x].rs,mid+1,r,t1,t2);
	}
	
	void mian(){
		cin>>n;
		for(int i=1;i<=n;i++){
			int k;cin>>k,p[i].resize(k);
			for(int j=0;j<k;j++)cin>>p[i][j],c[++num]=p[i][j];
		}

		cin>>C;
		for(int i=1;i<=n;i++)cin>>a[i];

		sort(c+1,c+1+num),num=unique(c+1,c+1+num)-c-1;
		for(int i=1;i<=n;i++){
			for(int &j:p[i]){
				j=lower_bound(c+1,c+1+num,j)-c;
				allp[j].push_back(i);
			}
		}

		//for(int i=1;i<=n;i++){
		//	cout<<"GOT "<<i<<endl;
		//	for(int j:p[i])cout<<j<<' ';
		//	cout<<endl;
		//}

		rt=++cnt;
		for(int i=1;i<=n;i++)las[i]=-1;
		for(int i=1;i<=num;i++){
			vector<int> q;
			//cout<<"IND "<<i<<' '<<c[i]<<endl;
			for(int j:allp[i]){
				if(las[j]!=-1){
					q.push_back(j);
					modify(rt,1,lim,1,c[i]-las[j],0,C);
					modify(rt,1,lim,c[i]-las[j]+1,lim,1ll*(c[i]-las[j])*C,0);
					//cout<<"MDF "<<j<<' '<<las[j]<<' '<<c[i]-las[j]<<' '<<1ll*(c[i]-las[j])*C<<endl;
				}
			}
			sort(q.begin(),q.end(),[&](int x,int y){return las[x]>las[y];});
			int cur=c[i],tot=allp[i].size();
			for(int j:q){
				if(las[j]==cur){
					tot--;
					continue;
				}
				modify(rt,1,lim,c[i]-cur+1,c[i]-las[j],1ll*a[tot]*tot,0);
				//cout<<"ADD "<<las[j]<<' '<<c[i]-cur+1<<' '<<c[i]-las[j]<<' '<<tot<<' '<<1ll*a[tot]*tot<<endl;
				cur=las[j],	tot--;
			}
			modify(rt,1,lim,c[i]-cur+1,lim,1ll*a[tot]*tot,0);
			for(int j:allp[i])las[j]=c[i];
		}
		
		t[rt].t2+=n;

		ans=linf,solve(rt,1,lim);
		cout<<ans<<' '<<res.size()<<endl;
		for(int i:res)cout<<i<<' ';
		cout<<endl;
	}
}

signed main(){
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	LinkWish::mian();
	return 0;
}